# Copyright 2025 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@pigweed//pw_build:compatibility.bzl", "incompatible_with_mcu")
load("@rules_platform//platform_data:defs.bzl", "platform_data")
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("//pw_build:python.bzl", "pw_py_binary")
load("//pw_kernel/tooling:code_size.bzl", "code_size")

rust_binary(
    name = "system_assembler",
    srcs = ["system_assembler.rs"],
    edition = "2024",
    tags = ["kernel"],
    target_compatible_with = incompatible_with_mcu(),
    deps = [
        "@rust_crates//:anyhow",
        "@rust_crates//:clap",
        "@rust_crates//:object",
    ],
)

rust_binary(
    name = "presubmit",
    srcs = ["presubmit.rs"],
    edition = "2024",
    tags = ["kernel"],
    target_compatible_with = incompatible_with_mcu(),
    visibility = ["//visibility:public"],
    deps = [
        "@rust_crates//:anyhow",
        "@rust_crates//:cliclack",
        "@rust_crates//:serde",
        "@rust_crates//:serde_json",
    ],
)

pw_py_binary(
    name = "qemu_runner",
    srcs = ["qemu_runner.py"],
    deps = [
        "//pw_tokenizer/py:detokenize",
        "@qemu//:qemu-system-arm-runfiles",
        "@qemu//:qemu-system-riscv32-runfiles",
        "@rules_python//python/runfiles",
    ],
)

platform_data(
    name = "qemu",
    platform = "@bazel_tools//tools:host_platform",
    target = ":qemu_runner",
)

platform_data(
    name = "serial_detokenizer",
    platform = "@bazel_tools//tools:host_platform",
    target = "//pw_tokenizer/py:serial_detokenizer",
)

# TODO: b/428960116 - migrate to bloaty
code_size(
    name = "code_size",
    binaries = [
        "//pw_kernel/target/mps2_an505/kernelspace_demo:kernelspace_demo",
        "//pw_kernel/target/mps2_an505/userspace_demo:userspace_demo",
        "//pw_kernel/target/qemu_virt_riscv32/kernelspace_demo:kernelspace_demo",
        "//pw_kernel/target/qemu_virt_riscv32/userspace_demo:userspace_demo",
    ],
    tags = ["kernel"],
)
